const ob = new IntersectionObserver(
  entries => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        const img = entry.target;
        img.src = img.dataset.url;
        ob.unobserve(img); // 取消监听
      }
    });
  },
  {
    threshold: 0
  }
);

const imgs = document.querySelectorAll("img[data-url]");

imgs.forEach(img => {
  ob.observe(img);
});
